package com.cloud.drore.eboss.operation.controller;


import com.cloud.drore.eboos.common.base.PagePo;
import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboos.common.entity.base.DictionaryVo;
import com.cloud.drore.eboos.common.entity.operation.po.FinaceFlowMeterCommonPo;
import com.cloud.drore.eboos.common.entity.operation.vo.FinaceFlowMeterCommonVo;
import com.cloud.drore.eboos.common.entity.operation.vo.FinaceOperationFlowMeterDetailsVo;
import com.cloud.drore.eboos.common.entity.supplier.po.FinaceOperationFlowMeterDetailsPo;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.operation.service.IBaseDataFeign;
import com.cloud.drore.eboss.operation.service.IFeignFinace;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 浙江卓锐科技股份有限公司 版权所有 © Copyright 2018<br>
 *
 * @Description: finace<br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/01/24 11:23 <br>
 * @Author: <a href="410508961@qq.com">夏凯</a>
 */
@RestController
@RequestMapping("/finaceOperation")
@Api(value = "/运营商财务接口流水", description = "运营商财务管理流水模块-夏凯")
public class FinaceOperationFlowController {

    @Autowired
    IBaseDataFeign iBaseDataFeign;
    @Resource
    IFeignFinace iFeignFinace;
    private static final int OPERATION_FEGIN_SERVICE_SUCCESS_CODE = 8200;

    @ApiOperation(value = "流水统计")
    @PostMapping(value = "/queryFlowMeterList")
    public ResultMessage<List<FinaceFlowMeterCommonVo>> feginQueryFlowMeterList(@RequestBody PagePo<FinaceFlowMeterCommonPo> page) throws BusinessException {
        ResultMessage<List<FinaceFlowMeterCommonVo>> listResultMessage = iFeignFinace.selectFlowMeterList(page);
        if (listResultMessage.getCode() != OPERATION_FEGIN_SERVICE_SUCCESS_CODE) {
            throw new BusinessException("远程调用或取流水失败！");
        }
        return listResultMessage;
    }

    @ApiOperation(value = "运营商查询流水明细")
    @PostMapping(value = "/queryFlowMeterListDetail")
    public ResultMessage<List<FinaceOperationFlowMeterDetailsVo>> queryFlowMeterListDetail(@RequestBody PagePo<FinaceOperationFlowMeterDetailsPo> page) throws BusinessException {
        if (null == page.getFields().getDistributorId() || "".equals(page.getFields().getDistributorId())) {
            throw new BusinessException("没有分销商id，非法请求！");
        }
        ResultMessage<List<FinaceOperationFlowMeterDetailsVo>> listResultMessage = iFeignFinace.queryFlowMeterListDetail(page);
        if (listResultMessage.getCode() != OPERATION_FEGIN_SERVICE_SUCCESS_CODE) {
            throw new BusinessException("远程调用或取流水失败！");
        }
        return listResultMessage;
    }

    @ApiOperation(value = "运营商订单流水订单明细初始化订单状态下拉框的筛选信息")
    @GetMapping(value = "/initOrderStatusList")
    public ResultMessage<List<DictionaryVo>> initOrderStatusList() {
        return ResultMessage.success(iBaseDataFeign.getDicListMapByCodeVo("ORDER_EVENT_STATUS"));
    }

}